﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Hello QWeb</title>
    <style type="text/css">
           body
           {
               font-family:Calibri;
               font-size:small;
           }
    </style>
</head>
<body>
    <h1>QWeb Sample Application #1 - Hello QWeb!</h1>
    <p>
        As described on <a href="http://code.google.com/p/comdivqweb/">project page</a>, QWeb designed to expose an API from server to some client
        without overheats with configuration, interface implementation and so on.
    </p>
    <p>
        This sample shows that we can just return a result in native API format of our application and QWeb will adapt it to remote client
    </p>
    <h2>Application configuration</h2>
    <p>
        Default basis configuration of QWeb is very and very simple:
        <ol>
            <li>reference Comdiv.QWeb library (no any external DLL needed)</li> 
            <li>prepare web.config:
                <br />
                <textarea cols="100" rows="12">
  <system.web>   
      <httpHandlers> <!-- for iis 6 and developer server only - remove it on IIS configuration -->
        <add path="*.qweb" verb="*" type="Comdiv.QWeb.QWebHandler, Comdiv.QWeb" validate="false"/>
      </httpHandlers>
    </system.web>
  <system.webServer>
    <handlers><!-- for iis 7 -->
      <add name="QWeb" path="*.qweb" verb="*" type="Comdiv.QWeb.QWebHandler, Comdiv.QWeb" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    </system.webServer>
                </textarea>
            </li>
        </ol>
    </p>
    <h2>Application API</h2>
    <p>
        In QWeb you expose your API through <strong>ACTIONS</strong>, in MVC terminology QWeb Actions may be treated as "controllers with one action".
    </p>
    <p>
        We have some reasones to create such design - atomizing of "controller" is a way for mo flexible security, performance and name-resolution managment. In
        most cases we see that both MonoRail, MS MVC controllers are created in TRANSIENT MODE and one Request in 99% of calls uses at least ONE method (action)
        of controller. But with controllers we have some troubles with URL namespaces, filters and "exclude filters" and so on.
    </p>
    <p>So due to reasones above in this sample we create API from 3 actions - "hello/string", "hello/class", "hello/minimal"</p>
    <ul>
        <li>hello/string (<a href="text_of_cs/HelloString.txt" target="_blank">HelloString.cs</a>) - shows return of single simple object that is very usual thing in any web application with rich Ajax support</li>
        <li>hello/class (<a href="text_of_cs/HelloClass.txt"  target="_blank">HelloClass.cs</a>) - shows return of complex object with nested sub-objects</li>
        <li>hello/minimal (<a href="text_of_cs/hello_minimal.txt"  target="_blank">hello_minimal.cs</a>) - shows minimalistic action definition - mostly zipped syntax </li>
    </ul>
    <h2>Rendering</h2>
    <p>That's all? We don't write any views, any rendering or render-managment code? We do nothing to configure our actions?????</p>
    <p>Yes! We don't know how out API will be used - may be client need JSON and will use it in Javascript-based application?... may be our API must be used as XML Web Service?...
    or may be someone will write view file and will want to get fully generated HTML, or may be ....</p>
    <p>So, generation is not more business of controller (and even of developer!!!)  in QWeb, engine provides variative set of rendering types to meet all requests</p>

    <h2>Try it!!!</h2>
    <p>Just click on this links and look at result:</p>
    <ul>
        <li>Calling hello/string</li>
        <ul>
            <li>As json: <a href="hello/string.json.qweb" target="_blank">hello/string.json.qweb</a></li>
            <li>As xml: <a href="hello/string.xml.qweb" target="_blank">hello/string.xml.qweb</a></li>
            <li>As md5 hash: <a href="hello/string.md5.qweb" target="_blank">hello/string.md5.qweb</a></li>
            <li>As view execution: <a href="hello/string.view.qweb" target="_blank">hello/string.view.qweb</a></li>
        </ul>
        
        <li>Calling hello/class</li>
        <ul>
            <li>As json: <a href="hello/class.json.qweb" target="_blank">hello/class.json.qweb</a></li>
            <li>As xml: <a href="hello/class.xml.qweb" target="_blank">hello/class.xml.qweb</a></li>
            <li>As md5 hash: <a href="hello/class.md5.qweb" target="_blank">hello/class.md5.qweb</a></li>
            <li>As view execution: <a href="hello/class.view.qweb" target="_blank">hello/class.view.qweb</a></li>
        </ul>
         <li>Calling hello/minimal</li>
        <ul>
            <li>As json: <a href="hello/minimal.json.qweb" target="_blank">hello/minimal.json.qweb</a></li>
            <li>As xml: <a href="hello/minimal.xml.qweb" target="_blank">hello/minimal.xml.qweb</a></li>
            <li>As md5 hash: <a href="hello/minimal.md5.qweb" target="_blank">hello/minimal.md5.qweb</a></li>
            <li>As view execution: <a href="hello/minimal.view.qweb" target="_blank">hello/minimal.view.qweb</a></li>
        </ul>
        <ul>
            <li>And... you always can run<a href="qweb/stats.xml.qweb" target="_blank">qweb/stats.xml.qweb</a></li>
        </ul>
    </ul>
    <h2>Conclusion</h2>
    <p>QWeb provides very easy to use framework for exposing your API in atomized actions. QWeb can find them and provides 
    unified way to generate mostly usual representations of execution result, with main accent on service/json providing </p>
    <p>soon i'll prepare more smart samples that will show how server dynamic application can make normal 304 response without
    strange and headbreaking "caching frameworks", how to make applicaiton more secure, how to extend QWeb and so on...
    </p>
    <p>Will be contunied...</p>
    <p><string>With best regards, Comdiv</string></p>
</body>
</html>
